<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include '../../operations/connection.php';

if(!isset($_SESSION['user']))
{
	header( 'Location: login.php' );
}
else
{
	$username = $_SESSION['fullname'];
	$id_employee = $_SESSION['IDEmployee'];
}
$a= (string)(microtime(true)*1000);
$b=split('\.',$a);
$idemployee= $b[0];

$usernames=$_REQUEST['username'];
$pass =strtoupper(md5($_REQUEST['password']));
$repass =$_REQUEST['repass'];
$fulln =$_REQUEST['fulln'];
$employeeCode =$_REQUEST['employeeCode'];
$identity =$_REQUEST['identity'];
$bankName =$_REQUEST['bankName'];
$bankAccount =$_REQUEST['bankAccount'];
if ($_REQUEST['birthday']==""){
	$birthday =date("Y-m-d",time());
}else{
	$birthday =$_REQUEST['birthday'];
}
if ($_REQUEST['startwork']==""){
	$startwork =date("Y-m-d", time());
}else {
	$startwork =$_REQUEST['startwork'];
}
$mail =$_REQUEST['mail'];
$mobile =$_REQUEST['mobile'];
$phone =$_REQUEST['phone'];
$address =$_REQUEST['address'];
$position =$_REQUEST['position'];
$currentJob =$_REQUEST['currentJob'];
$description =$_REQUEST['description'];
$department = $_REQUEST['department'];
$roleaccess = $_REQUEST['roleaccess'];
$sex = $_REQUEST['sex'];
$accountant = $_REQUEST['accountant'];
$typeempl = $_REQUEST['typeempl'];
$graduatedegree = $_REQUEST['graduatedegree'];
$startdatetrying=$_REQUEST['startdatetrying'];
$enddatetrying=$_REQUEST['enddatetrying'];
	if(isset($_REQUEST['register'])&& $_REQUEST['register']=="add"){
	$sqlinsert = "INSERT INTO employee(IDEmployee,UserName,Password, 
		FullName,IDManager,IDDepartment,IDRole,Phone,Birthday,Email,Address,Position,Sex,Accountant,
		StartDate,CMND,BankAccount,BankName,EmployeeCode,State,Mobile,Description,CurrentJob,Type_employee,StartDateProbation,EndDateProbation,GraduateDegree) 
					VALUES('$idemployee','$usernames','$pass','$fulln','$idemployee','$department','$roleaccess','$phone','$birthday','$mail',
					'$address','$position','$sex','$accountant','$startwork','$identity','$bankAccount','$bankName','$employeeCode',1,
					'$mobile','$description','$currentJob','$typeempl','$startdatetrying','$enddatetrying','$graduatedegree')";
	mysql_query($sqlinsert);
	
	$sqlinsertsalary = "INSERT INTO sa_regulation_salary(employeeID) VALUES('$idemployee')";
	mysql_query($sqlinsertsalary);
}

mysql_close($connection);


if(isset($_REQUEST['register'])){
	$_SESSION['successus']= "";
	if($typeempl==0)
		if($_SESSION['db']=='elitech')
			header("Location: ../../employee-trying-admin.php");
		else 
			header("Location: ../../employee-working-admin.php"); 
	else
		header("Location: ../../employee-working-admin.php"); 
}
ob_flush();

?>